define(function (require, exports, module) {
	var Grid = require("grid");
	var Dialog = require("dialog");
	
	var gridEvents = require("../handler/gridEvents");
	
    var instance = {
        initComponent: function (params, widget) {
            var grid = new Grid({
            	parentNode : ".J-grid",
            	url : "api/nonmemgroupreserve/query",
            	autoRender : false,
            	params : function(){
            		var subnav = widget.get("subnav");
            		var obj = {
            			//"nonMemberGroup.status" : subnav.getValue("status"),
            			"nonstatus" : subnav.getValue("status"),
            			"nonMemberGroup.servicePoint" : subnav.getValue("servicePoint"),
            			"nonMemberGroup.checkInDate" : subnav.getValue("startDate").start,
            			"checkInDateEnd" : subnav.getValue("startDate").end,
            			"nonMemberGroup.signUpType" : "NonMember",
            			"orderString:desc" : "nonMemberGroup.checkInDate",
            			fetchProperties : "*,nonMemberGroup.*,nonMemberGroup.servicePoint.name," +
            					"nonMemberGroup.servicePoint.pkServicePoint," +
            					"nonMemberGroup.operator.name," +
            					"nonMemberGroup.signUps.version,"+
            					"nonMemberGroup.contactName,"+
            					"nonMemberGroup.contactPhone,"+
            					"nonMemberGroup.checkInDate,"+
            					"nonMemberGroup.checkOutDate,"+
            					"nonMemberGroup.status,"+
            					"nonMemberGroup.signUpNumber,"+
            					"nonMemberGroup.perNumber,"+
            					"signUpRooms.*,"+
            					"signUpRooms.count,"+
            					"signUpRooms.roomType.*"
            					
            		}
            		return obj;
            	},
            	model : {
            		columns:[{
            			name : "nonMemberGroup.servicePoint.name",
            			label : "目的地",
            		},{
            			name:"nonMemberGroup.contactName",
            			label:"联系人"
            		},{
            			name:"nonMemberGroup.contactPhone",
            			label:"联系电话"
            		},{
            			name : "nonMemberGroup.checkInDate",
            			label : "入住日期",
            			format : "date"
            		},{
            			name : "nonMemberGroup.checkOutDate",
            			label : "退房日期",
            			format : "date"
            		},{
            			name:"signUpRooms.count",
            			label:"房型（数量）",
            			format:function(data,row){
            				var val = "";
            				for(var i = 0;i<row.signUpRooms.length;i++){
            					if(row.signUpRooms[i].roomType!=null){
            						val = val + row.signUpRooms[i].roomType.name + "("+row.signUpRooms[i].count+")"
            					}
            				}
            				return val;
            			}
            		},{
            			name : "nonMemberGroup.perNumber",
            			label : "入住人数",
            			/*format : function(data, row){
            				return row.nonMemberGroup.signUps.length;
            			}*/
            		},{
            			name : "nonMemberGroup.status",
            			label : "状态",
            			format : function(data, row){
            				var key = row.nonMemberGroup.status.key;
            				if(key == "Initial"){
            					return "待确认";
            				}else if(key == "Confirm"){
            					return "已确认"
            				}else if(key == "Effective") {
            					return "有效"
            				} else{
            					return "已预约"
            				}
            			}
            		},{
                        name : "show",
                        label : "操作",
    					format : "button",
						formatparams : [{
							id : "edit",
							text : "编辑",
							handler : function(index,data,rowEle){
								if(data.nonMemberGroup.status.key != "Initial"){
									Dialog.alert({
										tip : "提示",
										content : "确认和预约后无法重复修改！"
									})
								}else{
									gridEvents.editData(data, widget);
								}
							}
						},{
							id : "confirm",
							text : "确认",
							handler : function(index,data,rowEle){
								if(data.nonMemberGroup.status.key != "Initial"){
									Dialog.alert({
										tip : "提示",
										content : "确认和预约后无法重复确认！"
									})
								}else{
									gridEvents.confirmData(data, widget);
								}
							}
						},{
							id : "check",
							text : "查看",
							handler : function(index,data,rowEle){
								/*if(data.nonMemberGroup.status.key == "Initial"){
									Dialog.alert({
										tip : "提示",
										content : "未确认！"
									})
								}else{*/
									gridEvents.checkData(data, widget);
								//}
							}
						},{
							id : "delete",
							text : "删除",
							show:function(value,row){
								if(row.nonMemberGroup.status.key == "Initial"){
									return true;
								}else{
									return false;
								}
							},
							handler : function(index,data,rowEle){
								gridEvents.deleteData(data, widget);
							}
						}]
                    },]
        		}
            })
        	widget.set("grid", grid);
        }
    };
    module.exports = instance;
});
